package javaspaces;

import net.jini.space.JavaSpace;

public class Producer {

	private static final int MAX_MSGS = 30;

	public static void main(String args[]) {
		WorkEntry entry = new WorkEntry("A test msg", 0);
		WorkEntry template = new WorkEntry();
		JavaSpace space = Locator.getSpace();
		for (int i = 0; i < MAX_MSGS; i++) {
			try {
				space.write(entry, null, 60 * 60 * 1000);
				Thread.sleep(1000);
				entry = (WorkEntry) space.take(template, null, Long.MAX_VALUE);
				System.out.println("PRODUCER: "+entry);
				entry.increment();
			} catch (Exception e) {
				e.printStackTrace();
				System.out.println("-->>");
			}
		}

	}
}
